package com.hunnyhu.tools;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBHelper extends SQLiteOpenHelper {

	public static final String DATABASE_NAME = "xTools.db";

	public static final String T_SIGN = "sign";
	public static final String C_ID = "id";
	public static final String C_DATE_BEGIN = "begin_date";
	public static final String C_DATE_END = "end_date";
	public static final String C_DATE_CREATED = "date_created";
	public static final String C_LAST_UPDATED = "last_updated";

	private static final int DATABASE_VERSION = 1;
	// Database creation sql statement
	private static final String DATABASE_CREATE = "create table "
			+ T_SIGN + " (" 
			+ C_ID
			+ " integer primary key autoincrement, " 
			+ C_DATE_BEGIN
			+ " timestamp default null, " 
			+ C_DATE_END
			+ " timestamp default null, " 
			+ C_DATE_CREATED
			+ " timestamp default null, " 
			+ C_LAST_UPDATED
			+ " timestamp default null " 
			+ ");";

	public DBHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(DATABASE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(DBHelper.class.getName(), 
				"Upgrading database from version "
				+ oldVersion + " to " + newVersion
				+ ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + T_SIGN);
		onCreate(db);
	}

}
